/**
 * Copyright 2022-9999 the original author or authors.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.binghe.im.platform.message.controller;

import io.binghe.im.platform.common.model.enums.HttpCode;
import io.binghe.im.platform.common.model.vo.UploadImageVO;
import io.binghe.im.platform.common.response.ResponseMessage;
import io.binghe.im.platform.common.response.ResponseMessageFactory;
import io.binghe.im.platform.message.application.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author binghe(微信 : hacker_binghe)
 * @version 1.0.0
 * @description 文件接口
 * @github https://github.com/binghe001
 * @copyright 公众号: 冰河技术
 */
@RestController
@Api(tags = "文件上传")
public class FileController {

    @Autowired
    private FileService fileService;

    @ApiOperation(value = "上传图片",notes="上传图片,上传后返回原图和缩略图的url")
    @PostMapping("/image/upload")
    public ResponseMessage<UploadImageVO> uploadImage(MultipartFile file) {
        return ResponseMessageFactory.getSuccessResponseMessage(fileService.uploadImage(file));
    }

    @ApiOperation(value = "上传文件",notes="上传文件，上传后返回文件url")
    @PostMapping("/file/upload")
    public ResponseMessage<String> uploadFile(MultipartFile file) {
        return ResponseMessageFactory.getSuccessResponseMessage(fileService.uploadFile(file), HttpCode.SUCCESS.getMsg());
    }
}
